#include "Bomb.h"
#include "BitmapFont.h"
#include "..//SGD Wrappers//SGD_GraphicsManager.h"
#include "GameplayState.h"
#include <string>
#include <Windows.h>

std::wstring s2ws(const std::string& s);

Bomb::Bomb()
{
	m_hImage = SGD::GraphicsManager::GetInstance()->LoadTexture("resource//graphics//Bomb_Purple_Dark.png", SGD::Color(255, 255, 255, 255));
}


Bomb::~Bomb()
{
	SGD::GraphicsManager::GetInstance()->UnloadTexture(m_hImage);
}

void Bomb::Render()
{
	SGD::GraphicsManager* pGraphics = SGD::GraphicsManager::GetInstance();
	SGD::String time;
	BitmapFont font;
	font.Initialize();
	std::ostringstream tempTime;
	tempTime << GameplayState::GetInstance()->GetWorldTimer();
	time = SGD::String(s2ws(tempTime.str()));

	int Trackint = time.find_last_of(L".");
	if (Trackint != -1)
		time.erase(time.begin() + Trackint + 2, time.end());

	if (m_bAlive)
		pGraphics->DrawTexture(
		m_hImage,
		{
		m_ptPosition.x - GameplayState::GetInstance()->GetCamX(),
		m_ptPosition.y - GameplayState::GetInstance()->GetCamY()
	});
	font.Draw(&time, (int)(m_ptPosition.x - GameplayState::GetInstance()->GetCamX() + m_szSize.width / 2.0f - 60),
		(int)(m_ptPosition.y - GameplayState::GetInstance()->GetCamY() + m_szSize.height / 2.0f - 56.0f),
		.75f, SGD::Color(255, 255, 0, 0));
}

//std::wstring s2ws(const std::string& s)
//{
//	int len;
//	int slength = (int)s.length() + 1;
//	len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
//	wchar_t* buf = new wchar_t[len];
//	MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
//	std::wstring r(buf);
//	delete[] buf;
//	return r;
//}